using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Main.polls
{
    public partial class create : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                //Call constructor on new Poll
                Poll newPoll = new Poll(pollTitle.Value, pollQuestion.Value, pollSummary.Value);
                newPoll.StartDate = DateTime.Now;
                newPoll.EndDate = DateTime.Now;
                newPoll.UserID = (Guid)Membership.GetUser().ProviderUserKey;
                newPoll.IsPublic = true;

                //Check the options
                if (option1.Value != "")
                    newPoll.Options.Add(new Option(option1.Value));
                if (option2.Value != "")
                    newPoll.Options.Add(new Option(option2.Value));
                if (option3.Value != "")
                    newPoll.Options.Add(new Option(option3.Value));
                if (option4.Value != "")
                    newPoll.Options.Add(new Option(option4.Value));
                if (option5.Value != "")
                    newPoll.Options.Add(new Option(option5.Value));

                //Insert the poll into the database
                newPoll.Commit();
                //Redirect to show the poll
                Response.Redirect("show.aspx?id=" + newPoll.ID.ToString());
            }
        }
    }
}
